export default {
  install(Vue) {
    Vue.filter('date', (time, fmt) => {
      let date = new Date(time);
        function addZero(val) {
          if (val < 10) {
            val = '0' + String(val);
          }
          return val;
        }
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        let hour = date.getHours();
        let minute = date.getMinutes();
        let second = date.getSeconds();
        month = addZero(month);
        day = addZero(day);
        hour = addZero(hour);
        minute = addZero(minute);
        second = addZero(second);
        if (fmt === 'YYYY-MM-DD') {
          return year + '-' + month + '-' + day
        } else {
          return year + '-' + month + '-' + day + ' ' + hour + ':' + minute +  ':' + second;
        }
    });


  }
}
